<template>
  <div>
    <h2>上传图片</h2>
    <el-form>
      <el-form-item>
        <el-upload
            list-type="picture-card"
            :multiple="false"
            :action="uploadUrl"
            :limit="1"
            :on-success="onUploadSuccessIdCard"
        >
          <i class="el-icon-plus"></i>
        </el-upload>
      </el-form-item>
    </el-form>
    <span v-if="dialogImageUrl != ''">图片地址：
      <a target="_blank" v-if="dialogImageUrl != ''" :href="dialogImageUrl">{{ dialogImageUrl }}</a>
    </span>
    <br/>
  </div>
</template>

<script>
import service from "../../utils/request";

export default {
  name: "UploadImg",
  data() {
    return {
      dialogImageUrl: "",
      file_id: "",
      dialogVisible: false,
      //uploadUrl: "http://localhost:9090/fastDFSFile/upload", //文件上传地址
      uploadUrl: "", //文件上传地址
      datas: {},
    };
  },
  created() {
    this.uploadUrl = service.defaults.baseURL + "/fastDFSFile/upload"
  },
  methods: {
    onUploadSuccessIdCard(response) {
      this.file_id = response.data.fastDfsFile.fileId;
      this.datas = response.data.fastDfsFile;
      //this.dialogImageUrl = "http://192.168.229.141/" + response.data.fastDfsFile.filePath;
      this.dialogImageUrl = this.$baseImagePath+"/" + response.data.fastDfsFile.filePath;
    },
  },
};
</script>

<style scoped>
</style>
